package com.hippo.core

import android.app.Application
import android.content.res.Configuration
import android.util.Log
import com.hippo.core.core.manager.AppCrashHandler
import com.hippo.core.core.manager.FileManager
import com.tencent.mmkv.MMKV
import java.util.Locale


open class BaseApplication: Application() {

    companion object{
        var context:Application?= null
    }

    override fun onCreate() {
        super.onCreate()
        context = this

        MMKV.initialize(context, FileManager.getConfigPath(this))
        Log.i("sss", "onCreate: ${FileManager.getCrashPath(this)}")
        AppCrashHandler.newInstance().init(this)
        setAppLocale()
    }


    private fun setAppLocale() {
        val sharedPreferences = getSharedPreferences("Settings", MODE_PRIVATE)
        val languageCode = sharedPreferences.getString("language", "en")

        val resources = resources
        val configuration: Configuration = resources.configuration
        val locale: Locale = Locale(languageCode)
        Locale.setDefault(locale)
        configuration.setLocale(locale)
        resources.updateConfiguration(configuration, resources.displayMetrics)
    }

}